
// ById
function D(id) {
    return document.getElementById(id);
}
window.onload = function () {
    // 获取robot_name
    var robot_name = tool.getSearch("robot_name");
    // 获取wx_id
    var wx_id = tool.getSearch("wx_id");

    // 获取用户详情
    getUserInfo(robot_name, wx_id);
}

// 初始化交互
function initAjax(msg) {
    var event = document.createEvent('MessageEvent');
    var origin = window.location.protocol + '//' + window.location.host;
    event.initMessageEvent('MessageReceived', true, true, msg, origin, 1234, window, null);
    document.dispatchEvent(event);
}

// 全局接收消息事件
function messageReceived(res) {
    // alert(res)
    res = JSON.parse(res);
    if (res.code == 100) {
        var data = res.data;
        //获取用户详情
        if (res.type == "Friend/Get") {
            getUserInfoCallback(data);
        }
    } else {

    }
}

// 获取用户详情
function getUserInfo(robot_name, wxid) {
    var data_opt = {
        type: "Friend/Get",
        data: {
            robot_name: robot_name,
            wxid: wxid
        }
    }
    data_opt = JSON.stringify(data_opt);

    initAjax(data_opt);
}

// 获取用户详情--回调
function getUserInfoCallback(data) {
    // alert(JSON.stringify(data))
    data = {
        usernick: '我是昵称',
        wxid: 'wxid_2335412312',
        heardpic: '../assets/images/36d55e28202ceba349998477f2597eef.jpg',
        area: '四川 成都',
        origin: '通过扫一扫添加',
        mark: '你是风儿我是沙',
        belong: '我是上级账号',
        gender: 0
    }
    var html = '';
    html += '<img src="' + data.heardpic + '" class="avatar">';
    html += '<p class="nickname">';
    html += '<span>' + data.usernick + '</span>';
    html += '<i class="icon-jslt-' + (data.gender == 0 ? "07 famale" : "06 male") + '"></i>';
    html += '</p>';
    html += '<p class="account">账号：' + data.wxid + '</p>';
    html += '<div class="other">';
    html += '<p><span>备 注</span><span class="ellipsis">' + data.mark + '</span></p>';
    html += '<p><span>地 区</span><span class="ellipsis">' + data.area + '</span></p>';
    html += '<p><span>来 源</span><span class="ellipsis">' + data.origin + '</span></p>';
    html += '</div>';

    D("m-uinfo-main").innerHTML = html;
}